package com.topisv.tms.entity;

import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.hibernate.validator.constraints.NotBlank;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;

@Entity
@Table(name = "tbl_user")
public class User extends IdEntity {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String openPassword;//密码明文
	private String userId;//一号店用户userId
	private String mail;//邮箱
	private String oldPassword;//原始密码
	
	public String getMail() {
		return mail;
	}

	public void setMail(String mail) {
		this.mail = mail;
	}

	public String getOpenPassword() {
		return openPassword;
	}

	public void setOpenPassword(String openPassword) {
		this.openPassword = openPassword;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public String getSessionKey() {
		return sessionKey;
	}

	public void setSessionKey(String sessionKey) {
		this.sessionKey = sessionKey;
	}

	public String getMerchantId() {
		return merchantId;
	}

	public void setMerchantId(String merchantId) {
		this.merchantId = merchantId;
	}

	public String getYhdUserType() {
		return yhdUserType;
	}

	public void setYhdUserType(String yhdUserType) {
		this.yhdUserType = yhdUserType;
	}


	private String sessionKey;
	private String merchantId;
	private String yhdUserType;//一号店用户类型
	
	private String username;
	private String realname;
	private String plainPassword;
	private String password;
	private String salt;
	private String jobuuid;
	
	private Long departmentId;
	private Date lasttime;
	private Date created;
	private Date updated;
	private String status;
	
	private Long[] roles;
	
	private List<Role> roleList;
	
	private String customerCode;//客户编码 （如果user_type为：customer，此字段有效）
	
	public String getUserType() {
		return userType;
	}

	public void setUserType(String userType) {
		this.userType = userType;
	}

	public String getAreagroups() {
		return areagroups;
	}

	public void setAreagroups(String areagroups) {
		this.areagroups = areagroups;
	}

	public String getCustomers() {
		return customers;
	}

	public void setCustomers(String customers) {
		this.customers = customers;
	}


	private String customerName;
	
	private String userType;//用户类型 （paiu: 派友用户 customer: 商家用户）
	
	private String areagroups;//区域组 （如果user_type为：paiu，此字段有效）
	
	private String customers;//商户组 (如果user_type为：paiu，此字段有效)
	
	private List<String> areagroupLists; 
	@Transient
	@JsonIgnore
	public List<String> getAreagroupLists() {
		return areagroupLists;
	}

	public void setAreagroupLists(List<String> areagroupLists) {
		this.areagroupLists = areagroupLists;
	}


	private List<String> customerLists;
	@Transient
	@JsonIgnore
	public List<String> getCustomerLists() {
		return customerLists;
	}

	public void setCustomerLists(List<String> customerLists) {
		this.customerLists = customerLists;
	}

	@Transient
	public String getCustomerName() {
		return customerName;
	}

	public void setCustomerName(String customerName) {
		this.customerName = customerName;
	}

	@Column(name="customer_code")
	public String getCustomerCode() {
		return customerCode;
	}

	public void setCustomerCode(String customerCode) {
		this.customerCode = customerCode;
	}

	public User() {
	}

	public User(Long id) {
		this.id = id;
	}
	@Transient
	@JsonIgnore
	public List<Role> getRoleList() {
		return roleList;
	}

	public void setRoleList(List<Role> roleList) {
		this.roleList = roleList;
	}

	// 不持久化到数据库，也不显示在Restful接口的属性.
	@Transient
	@JsonIgnore
	public Long[] getRoles() {
		return roles;
	}

	public void setRoles(Long[] roles) {
		this.roles = roles;
	}

	// 不持久化到数据库，也不显示在Restful接口的属性.
	@Transient
	@JsonIgnore
	public String getPlainPassword() {
		return plainPassword;
	}

	public void setPlainPassword(String plainPassword) {
		this.plainPassword = plainPassword;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getSalt() {
		return salt;
	}

	public void setSalt(String salt) {
		this.salt = salt;
	}
	@NotBlank
	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}
	@NotBlank
	public String getRealname() {
		return realname;
	}

	public void setRealname(String realname) {
		this.realname = realname;
	}

	public String getJobuuid() {
		return jobuuid;
	}

	public void setJobuuid(String jobuuid) {
		this.jobuuid = jobuuid;
	}

	@Column(name="department_id")
	public Long getDepartmentId() {
		return departmentId;
	}

	public void setDepartmentId(Long departmentId) {
		this.departmentId = departmentId;
	}

	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
	public Date getLasttime() {
		return lasttime;
	}

	public void setLasttime(Date lasttime) {
		this.lasttime = lasttime;
	}
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
	public Date getUpdated() {
		return updated;
	}

	public void setUpdated(Date updated) {
		this.updated = updated;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
	public Date getCreated() {
		return created;
	}

	public void setCreated(Date created) {
		this.created = created;
	}
	
	@Transient
	public String getOldPassword() {
		return oldPassword;
	}

	public void setOldPassword(String oldPassword) {
		this.oldPassword = oldPassword;
	}

	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this);
	}
}